package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.battle.pve.PVEStage;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class PVEStageListResponse extends Response {

	private int page;
	private int maxPage;
	private List<SimpleStageInfo> list = Collections.emptyList();
	
	public static class SimpleStageInfo {
		public int id; // id
		public byte type; // 关卡类型
		public String name; // 关卡名
		public String icon; // 关卡图标
		public int star; // 通过此关卡的星级(0:未通过;1~3:已通过(1~3星))
		public byte state; // 状态(0:未解锁,1:已解锁)
		public int levelLimit;
		public SimpleStageInfo(Player player, PVEStage ref) {
			this.id = ref.getId();
			this.type = ref.getTemplate().getType();
			this.name = ref.getTemplate().getName();
			this.icon = ref.getTemplate().getIcon();
			this.star = ref.getStar();
			PVEStage previous;
			this.state = (byte) (player.getLevel() >= ref.getTemplate().getLevelLimit()
							&& ((previous = player.getPveStages().findPreviousStage(ref)) == null || previous.isPass())
							? 1 : 0);
			this.levelLimit = ref.getTemplate().getLevelLimit();
		}
	}
	
	public PVEStageListResponse(int serial, int page, int maxPage, Player player, List<PVEStage> list) {
		super(serial);
		this.page = page;
		this.maxPage = maxPage;
		this.list = new ArrayList<SimpleStageInfo>(list.size());
		for (int i = 0; i < list.size(); i++) {
			PVEStage stage = list.get(i);
			SimpleStageInfo info = new SimpleStageInfo(player, stage);
			this.list.add(info);
		}
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getMaxPage() {
		return maxPage;
	}

	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}

	public List<SimpleStageInfo> getList() {
		return list;
	}

	public void setList(List<SimpleStageInfo> list) {
		this.list = list;
	}

}
